package com.roncoo.education.course.service.api.biz;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.roncoo.education.course.common.req.TopicREQ;
import com.roncoo.education.course.service.dao.impl.mapper.entity.CourseTopic;
import com.roncoo.education.course.service.dao.impl.mapper.entity.Topic;
import com.roncoo.education.course.service.dao.service.CourseTopicService;
import com.roncoo.education.course.service.dao.service.TopicService;
import com.roncoo.education.util.base.Result;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@AllArgsConstructor
public class ApiCourseTopicBiz {

    private final CourseTopicService courseTopicService;

    private final TopicService topicService;

    public Result<Page<CourseTopic>> list() {
        Page<CourseTopic> list = courseTopicService.page(new Page<>(1, -1),Wrappers.<CourseTopic>lambdaQuery().eq(CourseTopic::getStatusId, 1)
                .eq(CourseTopic::getType,1)
                .orderByAsc(CourseTopic::getComplete)
                .orderByDesc(CourseTopic::getGmtCreate));
        return Result.success(list);
    }

    public Result<Page<Topic>> topicList(TopicREQ topicREQ) {
        Page<Topic> page = topicService.page(new Page<>(topicREQ.getPageCurrent(), topicREQ.getPageSize()),
                Wrappers.<Topic>lambdaQuery().eq(Topic::getCourseTopicId, topicREQ.getCourseTopicId())
                .eq(Topic::getStatusId, 1)
                .orderByDesc(Topic::getGmtCreate));
        return Result.success(page);
    }

}
